package com.prothink.controller.statistics;


import com.prothink.entity.CourseCollection;
import com.prothink.service.CourseCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 *课程收藏量控制层
 * @Date 2022 11 24
 */
@CrossOrigin
@Controller
@RequestMapping("CourseCollection")
public class CourseCollectionController {
    @Autowired
    private CourseCollectionService courseCollectionService;

    /**
     * 获取全部被收藏过的课程
     * @param courseCollection 课程收藏实体类
     * @return 所有被收藏过的课程
     */
    @ResponseBody
    @RequestMapping("/getCourseCollection")
    public List getCourseCollection(CourseCollection courseCollection){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(new Date());
        try {
            Date parse = simpleDateFormat.parse(format);
            courseCollection.setCollectionTime(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return courseCollectionService.getCourseCollection(courseCollection);
    }

    /**
     * 添加被收藏的课程信息
     * @param courseCollection 课程收藏量实体类
     * @return
     */
    @ResponseBody
    @RequestMapping("/addCourseCollection")
    public Integer addCourseCollection(CourseCollection courseCollection){
        return courseCollectionService.addCourseCollection(courseCollection);
    }
}
